package com.txy.webmanagement.control;

import com.txy.webmanagement.model.SysUser;
import com.txy.webmanagement.service.SysUserService;
import com.txy.webmanagement.utils.RequestDataUtils;
import com.txy.webmanagement.utils.SysParrentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "user")
public class SysUserControl {
    @Autowired
    private SysUserService sysUserService;

    @RequestMapping(value = "index")
    public String index() {

        return "user/index";
    }

    @RequestMapping(value = "gotoAdd")
    public String gotoAdd() {
        return "user/add";
    }

    @RequestMapping(value = "add")
    @ResponseBody
    public RequestDataUtils add(SysUser user) {
        RequestDataUtils req = new RequestDataUtils();
        Boolean boo = sysUserService.save(user);
        if (boo) {
            req.setCode(SysParrentUtils.successCode);
            req.setMessage(SysParrentUtils.successMsg);
        } else {
            req.setCode(SysParrentUtils.errorCode);
            req.setMessage(SysParrentUtils.addErrorMsg);
        }
        return req;
    }
}
